package cn.simon.free.redis.component;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.cglib.beans.BeanMap;

import java.util.Map;
import java.util.Objects;

/**
 * 对象转换
 *
 * @author simon
 * @date 2020/11/25 13:57
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BeanUtils<K, V> {

    /**
     * 对象转map
     *
     * @param bean 待转换对象
     * @param <K>  Key类型
     * @param <V>  Value类型
     * @return 返回的Map
     */
    public static <K, V> Map<K, V> beanToMap(Object bean) {
        return Objects.isNull(bean) ? null : BeanMap.create(bean);
    }

}
